package net.display;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.bo.KDemande;
import net.bo.KPlan;
import net.bo.KUtilisateur;
import net.ko.displays.KObjectDisplay;
import net.ko.framework.KoSession;
import net.ko.http.views.KPageList;
import net.ko.kobject.KListObject;
import net.ko.kobject.KObject;

public class DisplayPlanEtDemande extends KObjectDisplay {

	@Override
	public void beforeLoading(Class<? extends KObject> clazz, KPageList list, HttpServletRequest request) {
		HttpSession session = request.getSession();
		KUtilisateur user = (KUtilisateur) session.getAttribute("activeUser");
		list.addWhere("idUtilisateur=" + user.getId());

	}

	@Override
	public String showInList(KObject ko, String memberName, HttpServletRequest request) {
		String res = super.showInList(ko, memberName, request);
		KPlan plan = (KPlan) ko;

		if ("nbDemande".equals(memberName)) {
			KListObject<KDemande> demandes = KoSession.kloadMany(KDemande.class, "idPlan=" + plan.getId());
			res = String.valueOf(demandes.count());
		}

		return res;
	}
}